package chen.web.blog;

import java.util.Calendar;

public class ArchiveTime {

	private int year;
	private int month;
	
	public ArchiveTime(int year, int month){
		if(month < 0 || month > 12){
			throw new IllegalArgumentException("月份由1开始，必须是1到12");
		}
		this.year = year;
		this.month = month;
	}
	
	public int getBeginTimeStamp(){
		return (int)(getBeginCalendar().getTimeInMillis() / 1000);
	}
	
	private Calendar getBeginCalendar(){
		Calendar cal = Calendar.getInstance();
		cal.set(year, month-1, 1, 0, 0, 0);
		cal.set(Calendar.MILLISECOND, 0);
		return cal;
	}
	
	public int getEndTimeStamp(){
		Calendar cal = getBeginCalendar();
		cal.roll(Calendar.MONTH, true);
		return (int)(cal.getTimeInMillis() / 1000);
	}
}
